<template>
  <sea-dialog ref="dialog">

    <user-multiple-select ref="select1" v-if="multiple"
                          :span="6" :value="value"></user-multiple-select>

    <user-select ref="select2" v-if="!multiple"
                 :span="6" :value="value"></user-select>

    <template>
      <span class="pull-right">
        <el-button  @click="close">取 消</el-button>
        <el-button  type="primary" @click="submit">确 定</el-button>
      </span>
    </template>
  </sea-dialog>
</template>

<script>
/* eslint-disable */
import UserSelect from "../select";
import UserMultipleSelect from "../multiple-select";

/**
 * 选择用户弹窗
 */
export default {
    name: "UserSelectDialog"
    , components: {UserSelect, UserMultipleSelect}
    , props: {
        // 选择客户弹窗
        multiple: {type: Boolean, default: false}
        // 数值
        , value: {type: [String, Array], default: ''}
        // 选择确认后关闭
        , closeOnSelect: {type: Boolean, default: false}
        // 选中事件回调
        , onSelect: {type: Function, default: false}
    }
    , methods: {
        /**
         * 打开选择面板
         */
        open: function () {
            let dialog = {title: '选择用户', fullscreen: false, width: '70%'};
            this.$refs.dialog.open(dialog);
        }
        /**
         * 关闭弹窗
         */
        , close: function () {
            this.$refs.dialog.close();
        }
        /**
         * 确认选中
         */
        , submit: function () {
            if (this.onSelect !== undefined) {
                // 选中用户
                if (this.multiple) {
                    let ret = this.$refs.select1.getSelectUser();
                    this.onSelect(ret);
                } else {
                    let ret = this.$refs.select2.getSelectUser();
                    this.onSelect(ret);
                }
            }
            // 选择后立即关闭
            if (this.closeOnSelect) {
                this.close();
            }
        }
    }
}
</script>